/**
 * DozerListMapper.java
 * $Author: chris $
 *
 */
package uk.ac.manchester.tewpl.iceiface.server.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Roland
 * @version $Id: DozerListMapper.java,v 1.1 2009-08-13 17:51:34 chris Exp $
 * 
 */
public class DozerListMapper {
	@Autowired
	private DozerBeanMapper beanMapper;

	/**
	 * @param beanMapper
	 *            the mapper to set
	 */
	public void setBeanMapper(DozerBeanMapper beanMapper) {
		this.beanMapper = beanMapper;
	}

	public <T, E> Collection<E> map(Collection<T> sourceList, Class<E> destinationClass) {
		List<E> result = new ArrayList<E>();
		for (T o : sourceList) {
			result.add(destinationClass.cast(beanMapper.map(o, destinationClass)));
		}
		return result;
	}

	public <T> T map(T object, Class<T> destinationClass) {
		return destinationClass.cast(beanMapper.map(object, destinationClass));
	}
}
